package practise.alogrithm.hundredInterviewQuestions;

import com.sun.corba.se.spi.activation._RepositoryStub;

/**
 * Created by richard on 6/3/14.
 */
public class CalculateNumberOfPower {
    public static int calculate(int power,int base){
        int result = 1;
        if(base==0){
            throw new IllegalArgumentException();
        }
        if(power==0){
            return 1;
        }
        result = calculate(power/2, base);
        if(power%2==0){
            return result*result;
        }
        else{
            if(power<0){
                return result*result*(1/base);
            }
            return result*result*base;
        }
    }

    public static void main(String[] args){
        System.out.println("result: "+calculate(2,2));
    }


}
